<!--
* description: 缺件审核
* author: xiaochengzuan
* createdDate: 2021-1-28
-->
<template>
  <section class="editBigAreaInfo">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="popupsVisible"
      width="70%"
      @close="closeEdit"
      @open="open"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />

      <one-table-template
        ref="multipleTable"
        :dynamic-buttons="tableButtons"
        :dynamic-components="tableComponents"
        :dynamic-api-config="dynamicApiConfigs"
        :dynamic-table-cols="tableCols"
        :dynamic-form-fields="formField"
        :dynamic-is-show-select="false"
        :dynamic-is-init-table="true"
        :dynamic-api-style="'restful'"
        :callback-obj="callbackObj"
      >
        <template #bigAreaCode="scope">
            <el-input
              v-model="scope.row['bigAreaCode']"
              placeholder="审核意见"
              @input="bigAreaCodeChange($event, scope)"
            />
        </template>
      </one-table-template>
      <!-- <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :date-options-type="comp.dateOptionsType"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div> -->
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from '@/components/mixins/formMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import { orgApis } from '@/api/paSparePartsManagement'
export default {
  components: {
    OneTableTemplate,
    dialogHeader: () => import('@/components/dialogHeader'),
    mixButton: () => import('@/components/basicComponent/mixButton')
  },
  // 组件混入对象
  mixins: [formMixins],
  props: {
    popupsVisible: { type: Boolean, default: false },
    // 从网格传入的编辑行数据(json)
    dynamicEditRowData: { type: Object, default: function() { return {} } }
  },
  data() {
    const viewPageCode = 'bigAreaInfo-edit'
    return {
      selectiondata: null,
      dynamicApiConfigs: orgApis.shortageAuditMoreList,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey6',
          type: 'primary',
          size: 'small',
          icon: '',
          clickEvent: () => this.editReject(1),
          text: '通过',
          position: 'right'
        },
        {
          compKey: 'btnKey6',
          type: '',
          size: 'small',
          icon: '',
          clickEvent: () => this.editReject(2),
          text: '驳回',
          position: 'right'
        }
        // {
        //   compKey: 'btnKey1',
        //   type: 'primary',
        //   size: 'small',
        //   icon: 'iconfont  icon-preservation',
        //   clickEvent: () => this.save(),
        //   text: this.$t('sys.button.save') /* 保存*/,
        //   position: 'right'
        // },

        //  {
        //   compKey: 'btnKey2',
        //   type: '',
        //   size: 'small',
        //   name: 'reset',
        //   clickEvent: () => this.reset(),
        //   text: this.$t('sys.button.reset'),
        //   position: 'right' // 重置
        // },

        // {
        //   compKey: 'btnKey2',
        //   type: '',
        //   size: 'small',
        //   icon: 'iconfont  icon-cancel',
        //   clickEvent: () => this.close(),
        //   text: this.$t('sys.button.cancel') // 取消
        // }
      ],

      // 动态组件-查询条件
      tableComponents:

          [
            // {
            //   compKey: 'compKey1',
            //   labelName: '业务审核意见：',
            //   codeField: 'bigAreaCode',
            //   component: () => import('@/components/org/commonInput/textareaInput'),
            //   type: 'textarea',
            //   isRequire: true,
            //   isMust: true,
            //   span: 24
            // },

            //       {
            //   compKey: 'compKey1',
            //   labelName: '审核通过或驳回补贴资料，需填写操作说明:',
            //   codeField: 'logContent',
            //   validrule: { noRequire: true },
            //   component: () => import('@/components/org/commonInput/textareaInput'),
            //   type: 'textarea',
            //   isRequire: true,
            //   isMust: true,
            //   span: 24

            // }
            {
              compKey: 'compKey1',
              labelName: '缺件单号：',
              codeField: 'lackPartsCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: false,
              isMust: true,
              disabled: true
            },
            {
              compKey: 'compKey2',
              labelName: '关联类型: ',
              codeField: 'associationTypeCn',
              // component: () => import('@/components/org/LookupValue'),
              component: () => import('@/components/org/isEnable/isEnableOne'),
              type: 'dropdownList',
              //  oFields: 'statusId,statusText',
              //   options: [
              //   { statusId: '1', statusText: '启用' },
              //   { statusId: '0', statusText: '停用' }
              // ],
              //  isMul: false,
              isRequire: false,
              isMust: true,
              disabled: true
            },
            {
              compKey: 'compKey3',
              labelName: '关联单号：',
              codeField: 'associationNo',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: false,
              isMust: true,
              disabled: true
            },
            {
              compKey: 'compKey4',
              labelName: '缺件来源: ',
              codeField: 'lackPartsSource',
              // component: () => import('@/components/org/LookupValue'),
              component: () => import('@/components/org/isEnable/isEnableOne'),
              type: 'dropdownList',
              //  oFields: 'statusId,statusText',
              //   options: [
              //   { statusId: '1', statusText: '启用' },
              //   { statusId: '0', statusText: '停用' }
              // ],
              //  isMul: false,
              isRequire: false,
              isMust: true,
              disabled: true
            },
            {
              compKey: 'compKey5',
              labelName: '车牌号：',
              codeField: 'carLicense',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              isRequire: false,
              disabled: true
            },
            {
              compKey: 'compKey6',
              labelName: 'VIN：',
              codeField: 'vin',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              isRequire: false,
              disabled: true
            },
            {
              compKey: 'compKey7',
              labelName: '客户名称：',
              codeField: 'customerName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              isRequire: false,
              disabled: true
            },
            {
              compKey: 'compKey8',
              labelName: '联系电话：',
              codeField: 'customerPhone',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              isRequire: false,
              disabled: true
            },
            {
              compKey: 'compKey9',
              labelName: '登记人员：',
              codeField: 'registerPerson',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              isRequire: false,
              disabled: true
            },
            {
              compKey: 'compKey10',
              labelName: '紧急度: ',
              codeField: 'urgency',
              oFields: 'statusId,statusText',
              options: [
                { statusId: '1', statusText: '紧急' },
                { statusId: '0', statusText: '一般' }
              ],
              // component: () => import('@/components/org/LookupValue'),
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',

              //   options: [
              //   { statusId: '1', statusText: '启用' },
              //   { statusId: '0', statusText: '停用' }
              // ],

              //  isMul: false,
              isRequire: false,
              isMust: true,
              disabled: true
            },
            {
              compKey: 'compKey11',
              labelName: '备注：',
              codeField: 'remark',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              isRequire: false,
              span: 12,
              disabled: true
            }
            //  {
            //   compKey: 'compKey4',
            //   labelName: '所属期间：',
            //   codeField: 'bigAreaName2',
            //   component: () => import('@/components/org/datePicker/andtDatePicker'),
            //   type: 'andtDatePicker',
            //   isRequire: true,
            //   isMust: true
            // },

            //       {
            //     compKey: 'compKey3',
            //     labelName: '奖励项目: ',
            //     codeField: 'bigAreaName4',
            //     component: () => import('@/components/org/LookupValue'),
            //     type: 'dropdownList',
            //     //  oFields: 'statusId,statusText',
            //     //   options: [
            //     //   { statusId: '1', statusText: '启用' },
            //     //   { statusId: '0', statusText: '停用' }
            //     // ],
            //     isRequire: true,
            //     isMust: true
            //   },

          //       {
          //     compKey: 'compKey8',
          //     labelName: '申述截止时间：',
          //     codeField: 'bigAreaName6',
          //     component: () => import('@/components/org/datePicker/datePicker'),
          //     type: 'datePicker',
          //     isMul: false,
          //     isMust: true,
          //       isRequire: true,
          //   },
          ],
      tableCols: this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
            this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
            this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
              .length > 0
        ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
        : [
          {
            prop: 'releaseId',
            label: '主键ID',
            hidden: true,
            alwaysHidden: true
          },
          {
            prop: 'updateControlId',
            label: '并发控制ID',
            hidden: true,
            alwaysHidden: true
          },
          // {
          //   prop: 'controlBtn1',
          //   label: '操作',
          //   minWidth: 180,
          //   isComponent: true,
          //   comps: [
          //     {
          //       compKey: 'propKey1',
          //       labelName: '修改',
          //       component: () => import('@/components/org/linkButton'),
          //       clickEvent: (index) => this.edit(index)
          //     },
          //        {
          //       compKey: 'propKey1',
          //       labelName: '作废',
          //       component: () => import('@/components/org/linkButton'),
          //       clickEvent: (index) => this.edit(index)
          //     }
          //   ]
          // },
          {
            prop: 'partNo',
            label: '备件编号',
            hidden: false
            //   alwaysHidden: true
          },
          {
            prop: 'partName',
            label: '备件名称'
          },
          {
            prop: 'carConfigIdList',
            label: '备件类别'
          },
          {
            prop: 'partRepairType',
            label: '适用车型'
          },
          {
            prop: 'sjQty',
            label: '实际可用'
          },
          {
            prop: 'snp',
            label: 'SNP'
          },

          {
            prop: 'pointPriceTax',
            label: '参考价格'
          },
          {
            prop: 'userPrice',
            label: '销售价格'
          },
          {
            prop: 'lackQty',
            label: '缺件数量'
          },
          {
            prop: 'expectedDeliveryDate',
            label: '希望到货日期'
          },

          {
            prop: 'bigAreaCode',
            label: '审核意见',
            isSlot: true
          }

        ],
      callbackObj: {
        // 手动勾选时
        onCheckSelect: (selection, row) => {
          this.selectiondata = selection
          console.log(selection, row, 'selection')
        }
      },

      // 标题
      textMap: {
        edit: '缺件审核',
        add: '缺件信息维护'
      },

      // 表单数据（无需赋值，由混入对象赋值）
      formField: this.$utils.getFormField(this, {
        lackPartsCode: '',
        associationTypeCn: '',
        associationNo: '',
        lackPartsSource: '',
        carLicense: '',
        vin: '',
        customerName: '',
        customerPhone: '',
        registerPerson: '',
        urgency: '',
        remark: '',
        lackPartsId: '',
        updateControlId: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },
  mounted() {
    console.log(this.dynamicEditRowData)
  },
  methods: {
    // 关闭弹窗
    // handleClose(done) {
    //   this.$confirm('还未保存，确认关闭窗口？')
    //     .then(_ => {
    //       this.$emit('update:popupsVisible', false)
    //       done()
    //     })
    //     .catch(_ => {})
    // },
    // 审核意见发生变化触发
    bigAreaCodeChange(val, scope){
      // scope.row['bigAreaCode'] = ''
    },
    open() {
      this.$refs['multipleTable'].queryTable()
    },
    closeEdit() {
      this.$emit('update:popupsVisible', false)
    },
    // 新增/编辑保存按钮
    // save() {
    //   const that = this
    //   this.$utils.validataMoth(this, 'validpopup')
    //   if (this.valid) {
    //     if (that.popupsState === 'edit') {
    //       that.editSave()
    //     } else {
    //       that.addSave()
    //     }
    //   }
    // },
    // 驳回
    editReject(num) {
      const that = this
      const checkBox = { list: [] }
      checkBox.list = this.$refs['multipleTable'].list
      const queryObj = {
        apiConfig: orgApis.shortageAuditMoreListRejectedby,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: checkBox
      }
      if (num == 1) {
        queryObj.apiConfig = orgApis.shortageAuditMoreListExamine
        checkBox.lackPartsId = this.dynamicEditRowData.lackPartsId

        // this.selectiondata.forEach(function(val, index) {
        //   checkBox.list.push({
        //     lackPartsDId : val.LACK_PARTS_D_ID,
        //   })
        // })
      } else if (num == 2) {
        queryObj.apiConfig = orgApis.shortageAuditMoreListRejectedby
        // this.selectiondata.forEach(function(val, index) {
        //   checkBox.list.push({
        //     lackPartsDId : val.LACK_PARTS_D_ID,
        //   })
        // })
      }

      console.log(checkBox, this.selectiondata, 'checkBox')

      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then(response => {
        if (response.result === '1') {
          this.$message({
            message: response.msg,
            type: 'success',
            duration: 1000
          })
          this.popupsVisible = false
          this.$nextTick(() => {
            this.$parent.queryTable(1)
          })
        } else {
          // 保存失败
          this.$message({
            message: response.msg,
            type: 'warn',
            uration: 1000
          })
        }
        this.popupsVisible = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.promptSpan {
  position: absolute;
  bottom: 26px;
  right: 335px;
  color: #e70020;
}
</style>

